package org.xlp.db.xml;

import java.util.HashSet;
import java.util.Set;

/**
 * Description: 存储已解析的sql配置文件，防止死循环解析sql配置文件
 * <br/>date: 2024/4/16 10:33
 *
 * @version 1.0
 * @author: xlp
 */
class HasParseFileCache{
    private final static ThreadLocal<Set<String>> CACHE = new ThreadLocal<>();

    /**
     * 校验给定的路径是否解析过
     * @param path
     * @return true：已解析过，false：未解析
     */
    public static boolean hasParse(String path){
        Set<String> set = CACHE.get();
        if (set == null){
            set = new HashSet<>();
            CACHE.set(set);
            return false;
        }
        boolean contains = set.contains(path);
        if (!contains) set.add(path);
        return contains;
    }

    /**
     * 清空缓存
     */
    public static void clearCache(){
        CACHE.remove();
    }
}
